package com.pai4j.pgc.controller.community;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.common.config.annotation.RequestPermission;
import com.pai4j.common.enums.CommonStatusEnum;
import com.pai4j.common.helper.SessionHelper;
import com.pai4j.domain.community.vo.request.CCNavPathControlRequestVO;
import com.pai4j.domain.community.vo.request.CCNavPathRequestVO;
import com.pai4j.domain.community.vo.response.cc.CTCNavPathListResponseVO;
import com.pai4j.pgc.service.community.CCNavPathService;
import jakarta.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

/**
 *  技术社区导航路径
 *
 * @author: CYM-pai
 * @date: 2025/10/27 13:52
 **/
@RestController
@RequestMapping("/api/cc/nav/path")
public class CCNavPathController {

    @Autowired
    private CCNavPathService pathService;

    /***
     * 保存更新栏目
     * @param vo
     * @return
     */
    @RequestPermission
    @PostMapping("/save")
    public PAIResponseBean<Long> save(@Valid @RequestBody CCNavPathRequestVO vo) {
        return PAIResponseBeanUtil.success(pathService.save(vo, SessionHelper.getCurrentUserId()));
    }

    /***
     * 修改状态
     * @param vo
     * @return
     */
    @RequestPermission
    @PostMapping("/updateStatus")
    public PAIResponseBean updateStatus(@RequestBody CCNavPathControlRequestVO vo) {
        pathService.updateStatus(vo, SessionHelper.getCurrentUserId());
        return PAIResponseBeanUtil.success();
    }

    /***
     * 修改打标
     * @param vo
     * @return
     */
    @RequestPermission
    @PostMapping("/updateTag")
    public PAIResponseBean updateTag(@RequestBody CCNavPathControlRequestVO vo) {
        pathService.updateTag(vo, SessionHelper.getCurrentUserId());
        return PAIResponseBeanUtil.success();
    }

    /***
     * 查询所有栏目
     * @return
     */
    @RequestPermission
    @GetMapping("/admin.list")
    public PAIResponseBean<List<CTCNavPathListResponseVO>> list(
            @RequestParam(value = "ccId", required = false) Long ccId,
            @RequestParam(value = "status", required = false) String status) {
        // 返回给用户侧显示
        List<String> statusList = new ArrayList<>();
        if (StringUtils.isBlank(status)) {
            statusList = CommonStatusEnum.getAllEnableStatusDesc();
        } else {
            statusList.add(status);
        }
        return PAIResponseBeanUtil.success(pathService.list(ccId, statusList));
    }
}
